home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
RTF
/
textrect.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
4KB
|
167 lines
/* $Header: /usr/people/pcd/Src/RTF/RCS/textrect.h,v 1.1 92/11/23 12:58:52 pcd Exp Locker: pcd $
*/
#ifndef __textrect_h
#define __textrect_h
#include "textflow.h"
#define implies(p,q) assert(!(p) || (q))
class Box{
friend class LRBox; // for destroy
public:
Box(Box* prev);
~Box()
{ delete prev_; };
TextPosition position(const Extent&);
TextPosition format(const TextFlow*, TextPosition, TextPosition,
Extent, Extent&, int word_wrap = 0);
void render(const BRect&);
Coord locate(TextPosition, Coord, Coord) const;
Box* prev()
{ return prev_; };
void x(Coord xx, Coord w)
{ location.x = xx; width = w; };
void y(Coord yy); // affects prev
void move(Coord dx); // affects prev
Coord left()
{ return location.x; };
Coord right()
{ return location.x + width; };
TextPosition first() const
{ return f; }
protected:
Box* destroy()
{ Box* p = prev_; prev_ = 0; delete this; return p; };
private:
Box* prev_;
TextPosition f;
TextPosition first_;
const TextFlow* formnode;
Qty bytes;
Point location;
Coord width;
};
class LRBox{
friend class TextRect; // for destroy
public:
LRBox(LRBox* prev);
~LRBox()
{ delete runs; delete prev_; };
TextPosition format(const TextFlow*, TextPosition, TextPosition,
Extent, Extent&, int just=-1);
/* USE : pos = lrbox->format(flow, first, last, avail, used);
* assert(pos >= first && pos <= last);
*/
void render(const BRect&);
TextPosition position(Coord);
Coord locate(TextPosition) const;
TextPosition first()
{ return f; };
Coord y0() const
{ return y0_; };
LRBox* prev() const
{ return prev_; };
Coord top() const
{ return y0_; };
Coord bottom() const
{ return y0_ + ascent + descent; };
Coord height() const
{ return ascent + descent; };
protected:
LRBox* destroy()
{ LRBox* p = prev_; prev_ = 0; delete this; return p; };
private:
LRBox* prev_;
Box* runs;
Coord y0_;
Coord ascent, descent;
TextPosition f;
};
class TextRect{
/************
*
* A TextRect formats and renders information from a TextFlow.
*
************/
public:
TextRect();
/* USE : assert(textrect->region(first, last) < textrect->bounds());
*******/
~TextRect()
{ delete lines; };
/*******/
TextPosition
format(const TextFlow* tree, Qty first, Qty last,
const BRect& available);
/* DESC: compute sizes and positions of information from a TextFlow
* USE : assert(first <= last);
* last_formatted = textrect->format(tree, first, last, available);
* assert(first <= last_formatted);
* assert(last_formatted <= last);
* assert(textrect->bounds() <= available);
* @#BRect: x,y,w,h >= 0
* TIME: O(last-first) x TIME(TextFlow::character_shape())
*******/
/*******/
const BRect&
bounds() { return bounds_; };
/*
******/
/*******/
void
render(const BRect& exposed);
/* USE : textrect->render(exposed);
* TIME: @#
*******/
/***********/
TextPosition
position(Coord x, Coord y);
/* USE : pos = textrect->position(x, y);
* TIME: @#
***********/
/*******/
Coord
locate(TextPosition here, Coord* top=0, Coord* bottom=0) const;
/* USE : int x = textrect->locate(here, &top, ⊥
* assert(top<=bottom);
* int xx,yy; // FORALL
* TextPosition p = textrect->position(xx,yy);
* implies(yy<top, p<here);
* implies(yy>=bottom, p<here);
* implies(top<=yy&&yy<=bottom,
* xx<x == p<x);
*
*******/
private:
class LRBox* lines;
BRect bounds_;
};
#endif